<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

define( "JIEQI_MODULE_NAME", "system" );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( "system" );
jieqi_checkpower( $jieqiPower['system']['adminuser'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
include_once( JIEQI_ROOT_PATH."/class/users.php" );
$users_handler =& jieqiusershandler::getinstance( "JieqiUsersHandler" );
jieqi_getconfigs( JIEQI_MODULE_NAME, "configs" );
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) )
{
		$GLOBALS['_REQUEST']['page'] = 1;
}
include_once( JIEQI_ROOT_PATH."/admin/header.php" );
$jieqiTpl->assign( "checkall", "<input type=\"checkbox\" id=\"checkall\" name=\"checkall\" value=\"checkall\" onclick=\"javascript: for (var i=0;i<this.form.elements.length;i++){ if (this.form.elements[i].name != 'checkkall') this.form.elements[i].checked = form.checkall.checked; }\">" );
$criteria = new criteriacompo( );
if ( isset( $_REQUEST['keyword'], $_REQUEST['keyword'] ) )
{
		if ( $_REQUEST['keytype'] == "name" )
		{
				$criteria->add( new criteria( "name", $_REQUEST['keyword'], "=" ) );
		}
		else
		{
				$criteria->add( new criteria( "uname", $_REQUEST['keyword'], "=" ) );
		}
}
else if ( isset( $_REQUEST['groupid'], $_REQUEST['groupid'] ) )
{
		$criteria->add( new criteria( "groupid", $_REQUEST['groupid'], "=" ) );
}
$criteria->setsort( "uid" );
$criteria->setorder( "DESC" );
$criteria->setlimit( $jieqiConfigs['system']['useradminpnum'] );
$criteria->setstart( ( $_REQUEST['page'] - 1 ) * $jieqiConfigs['system']['useradminpnum'] );
$users_handler->queryobjects( $criteria );
$userrows = array( );
$k = 0;
while ( $v = $users_handler->getobject( ) )
{
		$userrows[$k]['checkbox'] = "<input type=\"checkbox\" id=\"checkid".$k."\" name=\"checkid".$k."\" value=\"".$v->getvar( "uid" )."\">";
		$userrows[$k]['userid'] = $v->getvar( "uid" );
		$userrows[$k]['username'] = $v->getvar( "uname" );
		$userrows[$k]['name'] = $v->getvar( "name" );
		if ( $userrows[$k]['name'] == "" )
		{
				$userrows[$k]['name'] = $userrows[$k]['username'];
		}
		$userrows[$k]['group'] = $v->getgroup( );
		$userrows[$k]['email'] = $v->getvar( "email" );
		$userrows[$k]['regdate'] = date( JIEQI_DATE_FORMAT, $v->getvar( "regdate" ) );
		$userrows[$k]['experience'] = $v->getvar( "experience" );
		$userrows[$k]['score'] = $v->getvar( "score" );
		$userrows[$k]['egold'] = $v->getvar( "egold" );
		$userrows[$k]['esilver'] = $v->getvar( "esilver" );
		$userrows[$k]['emoney'] = $userrows[$k]['egold'] + $userrows[$k]['esilver'];
		++$k;
}
$jieqiTpl->assign_by_ref( "userrows", $userrows );
$grouprows = array( );
$i = 0;
foreach ( $jieqiGroups as $k => $v )
{
		if ( 1 < $k )
		{
				$grouprows[$i]['groupid'] = $k;
				$grouprows[$i]['groupname'] = $v;
				++$i;
		}
}
$jieqiTpl->assign_by_ref( "grouprows", $grouprows );
$rowcount = $users_handler->getcount( $criteria );
$jieqiTpl->assign_by_ref( "rowcount", $rowcount );
include_once( JIEQI_ROOT_PATH."/lib/html/page.php" );
$jumppage = new jieqipage( $rowcount, $jieqiConfigs['system']['useradminpnum'], $_REQUEST['page'] );
$jumppage->setlink( "", true, true );
$jieqiTpl->assign( "url_jumppage", $jumppage->whole_bar( ) );
$jieqiTpl->setcaching( 0 );
$jieqiTset['jieqi_contents_template'] = JIEQI_ROOT_PATH."/templates/admin/users.html";
include_once( JIEQI_ROOT_PATH."/admin/footer.php" );
?>
